home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
010
/
blit.arc
/
BALLOC.C
< prev
next >
Wrap
Text File
|
1985-05-23
|
2KB
|
54 lines
/*
* name: balloc
*
* description: allocate a bitmap and return a pointer to it,
* using the rectangle r, which is the on-screen
* rectangle that corresponds to the bitmap image.
*
* synopsis: struct bitmap *balloc (r)
* struct rectangle *r;
*
* globals: none.
*
* calls: malloc (libc)
*
* called by: newlayer (newlayer.c)
* addobs (addobs.c)
*/
#include "layers.h"
struct bitmap *balloc (r)
struct rectangle *r;
{
struct bitmap *b;
int h;
int w;
int startbits;
int nwords;
int size;
char *malloc ();
/*
* allocate storage for a bitmap and return a pointer to it
*/
w = r -> corner.x - r -> origin.x;
h = r -> corner.y - r -> origin.y;
startbits = wordsize - (r -> origin.x % wordsize);
if (w <= startbits)
nwords = 1;
else
nwords = (w - startbits - 1) / wordsize + 2;
size = nwords * h + 1; /* the extra word is because of the way
my implementation of bitblt works */
b = (struct bitmap *) malloc ((unsigned) sizeof (struct bitmap));
b -> bm_base = (unsigned short *) malloc ((unsigned) (size * 2));
b -> bm_width = nwords;
b -> bm_rect.origin.x = r -> origin.x;
b -> bm_rect.origin.y = r -> origin.y;
b -> bm_rect.corner.x = r -> corner.x;
b -> bm_rect.corner.y = r -> corner.y;
b -> bm_obs = null; /* not used in a bitmap */
return (b);
}